﻿#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerInput.h"
#include "InputType.generated.h"



DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnKeyDownEvent, const FGeometry&, InGeometry, const FKeyEvent&, InKeyEvent);
DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnKeyUpEvent, const FGeometry&, InGeometry, const FKeyEvent&, InKeyEvent);



USTRUCT()
struct WIDGETGROUP_API FCustomKeyDelegateGroup
{
	GENERATED_BODY()
public:

	FCustomKeyDelegateGroup()
	{
		FCustomKeyDelegateGroup(nullptr);
	}

	FCustomKeyDelegateGroup(TArray<FInputActionKeyMapping>* inKeys)
		:Delegate_KeyDownEvent(), Delegate_KeyUpEvent()
	{
		Keys = inKeys;
		bDownActive = true;
		bUpActive = true;
	}
	~FCustomKeyDelegateGroup()
	{
		ClearKeys();
	}

	void ClearKeys()
	{
		Keys = nullptr;
	}

	void BindDownEvent(FOnKeyDownEvent inKeyDownEvent)
	{
		Delegate_KeyDownEvent.Clear();
		Delegate_KeyDownEvent = inKeyDownEvent;
	}
	void BindUpEvent(FOnKeyUpEvent inKeyUpEvent)
	{
		Delegate_KeyUpEvent.Clear();
		Delegate_KeyUpEvent = inKeyUpEvent;
	}

	FOnKeyDownEvent* GetDownEvent() { return &Delegate_KeyDownEvent; }
	FOnKeyUpEvent* GetUpEvent() { return &Delegate_KeyUpEvent; }

	bool HasBindDownEvent() { return Delegate_KeyDownEvent.IsBound(); }
	bool HasBindUpEvent() { return Delegate_KeyUpEvent.IsBound(); }

	void ClearDownEvent() { Delegate_KeyDownEvent.Clear(); }
	void ClearUpEvent() { Delegate_KeyUpEvent.Clear(); }

	bool HasThisKey(const FInputActionKeyMapping& Mapping)
	{
		if (Keys)
		{
			return Keys->Contains(Mapping);
		}
		return false;
	}

	bool bDownActive;
	bool bUpActive;
	TArray<FInputActionKeyMapping>* Keys;
protected:

	UPROPERTY()
		FOnKeyDownEvent Delegate_KeyDownEvent;
	UPROPERTY()
		FOnKeyUpEvent Delegate_KeyUpEvent;

};


